﻿using System.Configuration;

namespace mal.balades.Business.DataModel
{
    public partial class BaladesDataContext
    {
        private static string connectionStringName;

        public static string ConnectionStringName
        {
            get {return BaladesDataContext.connectionStringName; }
           set { BaladesDataContext.connectionStringName = value; }
        }

        public static string ConnectionString
        {
            get
            {
                if (string.IsNullOrEmpty(BaladesDataContext.connectionStringName))
                {
                    ConfigurationErrorsException cee1 = new ConfigurationErrorsException("BaladesDataContext.ConnectionStringName can not be null");
                    //MalLogManager.BusinessLogger.Error(cee1.Message, cee1);
                    throw cee1;
                }

                ConnectionStringSettings connectionString = ConfigurationManager.ConnectionStrings[BaladesDataContext.connectionStringName];
                if (connectionString == null)
                {
                    ConfigurationErrorsException cee2 = new ConfigurationErrorsException(string.Format("the connection string {0} can not be null", BaladesDataContext.connectionStringName));
                    //MalLogManager.ServiceLogger.Error(cee2.Message, cee2);
                    throw cee2;
                }

                return connectionString.ToString();
            }
        }

        public static BaladesDataContext Instance
        {
            get
            {
                BaladesDataContext instance = new BaladesDataContext(ConnectionString);
                return instance;
            }
        }
    }
}
